﻿/*

  The contents of this file are subject to the Mozilla Public License Version
  1.1 (the "License"); you may not use this file except in compliance with
  the License. You may obtain a copy of the License at 
  
           http://www.mozilla.org/MPL/ 
  
  Software distributed under the License is distributed on an "AS IS" basis,
  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  for the specific language governing rights and limitations under the License. 
  
  The Original Code is AST'r Framework.
  
  The Initial Developer of the Original Code is
  ALCARAZ Marc (aka eKameleon) <ekameleon@gmail.com>.
  Portions created by the Initial Developer are Copyright (C) 2004-2011
  the Initial Developer. All Rights Reserved.
  
  Contributor(s) :
  
 */
package egallery.basic.display
{
    import egallery.basic.logging.logger;

    import graphics.display.Background;

    import flash.display.Loader;
    import flash.events.Event;
    import flash.events.ProgressEvent;
    
    /**
     * This display contains a container to show an external picture.
     */
    public class Picture extends Background
    {
        /**
         * Creates a new Picture instance.
         */
        public function Picture()
        {
        	//
        }
        
        /**
         * The Loader reference in the picture display.
         */
        public var loader:Loader ;
                
        /**
         * Invoked to debug the event propagation.
         */     
        public function debug( event:Event = null ):void 
        {
            logger.debug( this + " debug " + event) ;
        }
        
        /**
         * Invoked when the loading is finished.
         */     
        public function init( event:Event = null ):void 
        {
            logger.debug( this + " init." ) ;
            update() ;
        }
        
        /**
         * Invoked when the loading is in progress.
         */
        public function progress(event:ProgressEvent):void 
        {
            logger.info("progressHandler: bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal);
        }
        
        /**
         * This method is invoqued after the draw() method in the update() method in this display.
         */
        protected override function viewChanged():void
        {
            if ( stage != null )
            {
                x = ( stage.stageWidth  - w ) / 2 ;
                y = ( stage.stageHeight - h ) / 2 ;
            }
            if ( loader != null )
            {
                loader.x = ( w - loader.width ) / 2  ;
                loader.y = ( h - loader.height ) / 2  ;
            }
        }
    }
}
